using FFTW
using WAV
using DSP
using SampledSignals
using Plots
audio_one_channel = SampleBuf(rand(100000), 10000)
audio_two_channel = SampleBuf(rand(100000,2), 10000)
audio_multi_channel = SampleBuf(rand(100000,2), 10000)
typeof(audio_one_channel.data)
Vector{Float64} (alias for Array{Float64, 1})
sizeof(audio_one_channel)
16
size(audio_one_channel)
(100000,)
sizeof(audio_one_channel.data)
800000
audio_one_channel.samplerate
10000.0
squarewave(x::Real) = ifelse(mod2pi(x) < π, 1.0, -1.0)
squarewave (generic function with 1 method)
function squarewave(x::Real, θ::Real)
0 ≤ θ ≤ 1 || throw(DomainError(θ, "squwarewave(x, θ) is only defined for 0 ≤ θ ≤ 1."))
ifelse(mod2pi(x) < 2π * θ, 1.0, -1.0)
end
squarewave (generic function with 2 methods)
function trianglewave(x::Real)
modx = mod2pi(x + π/2)
ifelse(modx < π, 2modx/π - 1, -2modx/π + 3)
end
trianglewave (generic function with 1 method)
sawtoothwave(x::Real) = rem2pi(x, RoundNearest) / π
sawtoothwave (generic function with 1 method)
plot([squarewave], -2π, 2π)
plot([sin], -2π, 2π)
plot([sawtoothwave], -2π, 2π)
plot([trianglewave], -2π, 2π)
A = .8; phi = π/2; f0= 1000; fs = 44100;
t = -0.002:1/fs:10*0.002
y = A*cos.(2*pi*f0*t .+ phi)
plot(t, y)
wavplay(y, fs)
A1 = .8; A2 = .8; phi1 = π/2; phi2 = π/2;
f01 = 1000; f02 = 1000; fst = 44100;
tr = -0.002:1/fs:0.002
y1 = A1*sin.(2*pi*f01*tr .+ phi1)
y2 = A2*cos.(2*pi*f02*tr .+ phi2)
addresult =y1 .+ y2
subresult =y1 .- y2
mulresult =y1 .* y2
divresult =y1 ./ y2
wavplay(subresult, fst)
plot(tr, y1)
plot(tr, y2)
plot(tr, addresult)
plot(tr, subresult)
plot(tr, mulresult)
plot(tr, divresult)
wave1, fs1 = wavread(joinpath("data", "piano-phrase.wav"))
wavplay(wave1, fs1)
fs1
44100.0f0
Az = .8; phiz = π/2; fsd = 44100;
tw = 0.0:1/fsd:(length(wave1)-1)/fsd
plot(tw, wave1[:,1])
plot(abs.(fft(wave1)).^2)
plot(tw[1:div(3end,16)], wave1[1:div(3end,16),1])
plot(tw[2000:35000], wave1[2000:35000,1])
wavplay(wave1[2000:35000,1], fs1)
plot(abs.(fft(wave1[2000:35000,1])).^2)
plot(0:1/fs1:(length(wave1)-1)/fs1, wave1, xlabel= "Time [s]")
Az = .8; phiz = π/2; fsd = 44100;
f0z = 880
tz = 1:1/fsd:11
wavez = Az./tz.*sin.(2*pi*f0z*tz .+ phiz);
wavplay(wavez, fsd)
f1 = 200; f2= 400; f3 = 600; f4 = 800; f5 = 1000;
ta = -0.005:1/fsd:0.005
harmonic1 = A*sin.(2*pi*f1*ta .+ phi)
harmonic2 = A*sin.(2*pi*f2*ta .+ phi)
harmonic3 = A*sin.(2*pi*f3*ta .+ phi)
harmonic4 = A*sin.(2*pi*f4*ta .+ phi)
harmonic5 = A*sin.(2*pi*f5*ta .+ phi)
nothing
wavplay(harmonic5, fsd)
composite = harmonic1 .+ harmonic2 .+ harmonic3 .+ harmonic4 .+harmonic5
nothing
plot(ta,composite)
wavplay(composite, fsd)